var choosetype = "轻松租车";
$(document).ready(function() {
					pageLoad();
					PageLoadTime();
					requestRent();
					pageChooseTime();
					pageBannerChoose();
					pageBannerjs();
					pageHelpjs();
					requestLineClick();
					requestRentClick();
					requestChinacity();
					requestChinacityinfo("北京");
					rentGoto();
					wantLine("面朝大海");
					wantHotLine();
					wantCity(1);
					clickcity();
					wantBanner();
					gotoLineIndex();
					ChooseRentTime();
					WantHotCity();



					
});
//首页选择时间功能
var ChooseRentTime = function(){
	laydate.render({
		  elem: '#chooseGotime', //指定元素,
		  min:new Date().Format("yyyy-MM-dd")
	});
	laydate.render({
		  elem: '#chooseBacktime', //指定元素,
		  min:new Date().Format("yyyy-MM-dd")
	});
	laydate.render({
		  elem: '#quchetimes', //指定元素,
		  min:new Date().Format("yyyy-MM-dd"),
		  position: 'static',
		  change: function(value, date){ //监听日期被切换
		  	$('#quchetimes').hide()
		    lay('.haiCar').val(value);
		  }
		  // type: 'datetime'
	});

	$(document).on('click',function(e){
		e.stopPropagation();
		$('#quchetimes').hide()
	})


	$('.haiCar').on('click',function(e){
		e.stopPropagation();
		$('#quchetimes').show()
	})
	$("input.index_choosemode_one_right_time_start_item").click(function(e){
		e.stopPropagation();
		$("div.index_choosemode_one_right_timechoose").removeClass("hidden");
		$("div.index_choosemode_one_right_timechoose").focus();
		$("div.index_choosemode_one_right_timechoosereturn").addClass("hidden");
	});
		//绑定选择出发时间事件
		for(var i=0;i<48;i++){
			$("div.index_choosemode_one_right_timechoose_right:eq(0)>div.index_choosemode_one_right_timechoose_right_item:eq("+i+")").click(function(i){
				return function(e){
					e.stopPropagation();
					var time = $("div.index_choosemode_one_right_timechoose_right:eq(0)>div.index_choosemode_one_right_timechoose_right_item:eq("+i+")").text();
					$("input.index_choosemode_one_right_time_start_item").val(time);
					$("div.index_choosemode_one_right_timechoose").addClass("hidden");
					CountRentTime();
					
				}
			}(i))
		};
	
	$("input.index_choosemode_one_right_time_return_item").click(function(e){
		e.stopPropagation(e);
		$("div.index_choosemode_one_right_timechoosereturn").removeClass("hidden");
		$("div.index_choosemode_one_right_timechoosereturn").focus();
		$("div.index_choosemode_one_right_timechoose").addClass("hidden");
	});
		//绑定选择返回时间事件
		for(var i=0;i<48;i++){
			$("div.index_choosemode_one_right_timechoose_right:eq(1)>div.index_choosemode_one_right_timechoose_right_item:eq("+i+")").click(function(i){
				return function(e){
					e.stopPropagation();
					var etime = $(this).text();
//					endhour = $(this).data("time");
					$("input.index_choosemode_one_right_time_return_item").val(etime);
					$("div.index_choosemode_one_right_timechoosereturn").addClass("hidden");
					CountRentTime();
				}
			}(i))
		};
	$("div").not("div.index_choosemode_one_right_timechoose").click(function(){
		$("div.index_choosemode_one_right_timechoose").addClass("hidden");
		CountRentTime();
	});
	$("div").not("div.index_choosemode_one_right_timechoosereturn").click(function(){
		$("div.index_choosemode_one_right_timechoosereturn").addClass("hidden");
		CountRentTime();
	});
	//只要鼠标移动到选择选择时间区域就会执行计算时间差动作
	$("div.index_choosemode_one").mouseover(function(){
		CountRentTime();
	});
	//设置title
	$(document).attr("title","搜房车 | 领先的房车自驾游租车平台，300+城市门店，5000+辆自动档房车，C照轻松租");//修改title值  
}
//计算出发返程时间差
var CountRentTime = function(){
	var startdate = $("input#chooseGotime").val();
	var enddate = $("input#chooseBacktime").val();
	var starthour = $("input#chooseGohour").val();
	var endhour = $("input#chooseBackhour").val();
	startdate = startdate.replace(/-/g,"/");
	enddate = enddate.replace(/-/g,"/");
	var sd = startdate + " " + starthour + ":00";
	var ed = enddate + " " + endhour + ":00";
	//处理时间
	var stime = new Date(sd);
	var etime = new Date(ed);
	var usedTime = etime - stime;
	var days=Math.floor(usedTime/(24*3600*1000));  
    //计算出小时数  
    var leave1=usedTime%(24*3600*1000);    //计算天数后剩余的毫秒数  
    var hours=Math.floor(leave1/(3600*1000));  
    //计算相差分钟数  
    var leave2=leave1%(3600*1000);        //计算小时数后剩余的毫秒数  
    var minutes=Math.floor(leave2/(60*1000));  
	
	var up = days + "天";
	var down = hours + "小时" + minutes + "分钟";
	$("div.index_choosemode_one_right_time_center_time_up").text(up);
	$("div.index_choosemode_one_right_time_center_time_down").text(down);
	
}
//是否可以跳转判定
var TestGoToList = function(){
	var startdate = $("input#chooseGotime").val();
	var enddate = $("input#chooseBacktime").val();
	var starttime = $("input.index_choosemode_one_right_time_start_item").val();
	var endtime = $("input.index_choosemode_one_right_time_return_item").val();
	startdate = startdate.replace(/-/g,"/");
	enddate = enddate.replace(/-/g,"/");
	var start = startdate + " " + starttime + ":00";
	var end = enddate + " " + endtime + ":00";
	var sd = new Date(start);
	var ed = new Date(end);
	var now = new Date();
	console.log("start="+start);
	console.log("sd="+sd);
	console.log("end="+end);
	console.log("ed="+ed);
	if(sd >= ed){
//		alert("选择开始时间不能大于结束时间！");
		layer.msg("选择开始时间不能大于结束时间！");
		return(0);
	};
	if(sd <= now){
//		alert("选择开始时间不能小于现在时间！");
		layer.msg("选择开始时间不能小于现在时间！");
		return(0)
	};
	return(1);		
}
//banner中的搜索跳转
var pageChooseTime = function(){
	//立即选车跳转
	$("input#chooseTimenow").click(
			function(e) {
				e.stopPropagation();
				var test = TestGoToList();
				if(test == 1){
					var startDate = $("#chooseGotime").val();
					var endDate = $("#chooseBacktime").val();
					var rentcity=$("input#chooseGocity").val();
					var starthour = $("input#chooseGohour").val();
					var endhour = $("input#chooseBackhour").val();
					var url = basePath+"/rentlist?rentcity="+rentcity+"&startDate="+startDate+"&endDate="+endDate+"&starthour="+starthour+"&endhour="+endhour;
					url = encodeURI(url);
					url = encodeURI(url);
					//重点步骤，转码2次，实现传参不出中文乱码或问号
					window.location.href = (url);
//					window.location.href = (basePath+"/rentindex?rentcity="+rentcity+"&startDate="+startDate+"&endDate="+endDate+"&starthour="+starthour+"&endhour="+endhour);
				};	
	});
	//房车旅行搜索跳转
	$("button.index_choosemode_two_b").click(function(e){
		e.stopPropagation();
		var linecity = $("input.index_choosemode_two_destinaton_input_input").val();
		if(linecity == ""){
			linecity = "深圳";
		};
		var url = basePath+"/linelist?linecity="+linecity;
		url = encodeURI(url);
		url = encodeURI(url);
		window.location.href = (url);
	});
	//超级保障跳转
	$("button.index_choosemode_three_right_b").click(function(e){
		e.stopPropagation();
		window.location.href = (basePath+"/superinsurance");
	});
	$("input.index_supercontent_left_item_icon_bposi").click(function(e){
		e.stopPropagation();
		window.location.href = (basePath+"/superinsurance");
	});
	
}
//banner功能栏的选择效果,点击切换css及对应div出现
var pageBannerChoose = function(){
	// banner功能栏的选择效果,点击切换css及对应div出现
	$("div.index_choosemode_left>div:eq(0)").click(
			function(e) {
				e.stopPropagation();
				$(this).attr("class","index_choosemode_left_item_choose");
				$("div.index_choosemode_left>div").not(this).attr("class","index_choosemode_left_item");
				$("div.index_choosemode_right>div:eq(0)").css("display", "block");
				$("div.index_choosemode_right>div").not("div.index_choosemode_right>div:eq(0)").css("display", "none");
			});
	$("div.index_choosemode_left>div:eq(1)").click(
			function(e) {
				e.stopPropagation();
				$(this).attr("class","index_choosemode_left_item_choose");
				$("div.index_choosemode_left>div").not(this).attr("class","index_choosemode_left_item");
				$("div.index_choosemode_right>div:eq(1)").css("display", "block");
				$("div.index_choosemode_right>div").not("div.index_choosemode_right>div:eq(1)").css("display", "none");
				pageBannerjs2()
			});
	$("div.index_choosemode_left>div:eq(2)").click(
			function(e) {
				e.stopPropagation();
				$(this).attr("class","index_choosemode_left_item_choose");
				$("div.index_choosemode_left>div").not(this).attr("class","index_choosemode_left_item");
				$("div.index_choosemode_right>div:eq(2)").css("display", "block");
				$("div.index_choosemode_right>div").not("div.index_choosemode_right>div:eq(2)").css("display", "none");
			});
	$("div.index_choosemode_left>div:eq(3)").click(
			function(e) {
				e.stopPropagation();
				$(this).attr("class","index_choosemode_left_item_choose");
				$("div.index_choosemode_left>div").not(this).attr("class","index_choosemode_left_item");
				$("div.index_choosemode_right>div:eq(3)").css("display", "block");
				$("div.index_choosemode_right>div").not("div.index_choosemode_right>div:eq(3)").css("display", "none");
			});
}
//banner房车租赁js
var pageBannerjs = function(){	
	$("#chooseGocity").click(
			function(e) {
				e.stopPropagation();
				$(".index_choosemode_one_right_city").removeClass("hidden");
				$(".index_choosemode_one_right_city").focus();
			}); // 选择城市得到焦点触发
	$("#chooseBackcity").click(
			function(e) {
				e.stopPropagation();
				$(".index_choosemode_one_right_city").removeClass("hidden");
				$(".index_choosemode_one_right_city").focus();
			}); // 选择城市得到焦点触发
	//判断哪种浏览器，如果为ie或safair则特俗对待
}

var pageBannerjs2 = function(){
	console.log(1)
	$(".quCar").click(
			function(e) {
				e.stopPropagation();
				$(".index_choosemode_one_right_city").removeClass("hidden");
				$(".index_choosemode_one_right_city").focus();
	})
}
//鼠标移动至帮助中心图片变换，字体颜色变换
var pageHelpjs = function(){
	var strFullPath=window.document.location.href;  
    var strPath=window.document.location.pathname;  
    var pos=strFullPath.indexOf(strPath);  
    var prePath=strFullPath.substring(0,pos);  
    var postPath=strPath.substring(0,strPath.substr(1).indexOf('/')+1);  
    var basePath = prePath;  
    basePath = prePath + postPath;//获取项目根目录
    imgb=basePath+"/static/pcsofangche/index/index/";
	for (var i = 0; i < 9; i++) {
		$(".index_help_content_left_content_item:eq(" + i + ")").mouseenter(
						function(i) {
							return function(e){
								e.stopPropagation();
								$(".index_help_content_left_content_item_icon_posi:eq("+ i + ")").attr("src",imgb+"img/index_help_" + (i + 1)+ "2.png");
								$(".index_help_content_left_content_item_word:eq("+ i + ")").css("color", "#FDD000");
								console.log(i);
								console.log("地址为"+ $(".index_help_content_left_content_item_icon_posi:eq("+ i + ")")[0].src);
							}	
						}(i));
		$(".index_help_content_left_content_item:eq(" + i + ")").mouseleave(
						function(i) {
							return function(e){
								e.stopPropagation();
								$(".index_help_content_left_content_item_icon_posi:eq("+ i + ")").attr("src",imgb+"img/index_help_" + (i + 1)+ "1.png");
								$(".index_help_content_left_content_item_word:eq("+ i + ")").css("color", "#999999");
							}				
						}(i)); 
	};
	//帮助中心跳转
	$("div.indexc_night a").attr("href",basePath+"/notFound");
}
//首页banner中房车租赁城市请求
var wantCity = function(type){
	$.ajax({
		dataType : "json",
		type : "post",
		url : basePath+"/carsearch",
		data : {
			type : type
		},
		contentType : "application/x-www-form-urlencoded;charset=utf-8",

		success : function(data) {
			var s = "";
			for (var y = 0; y < data.data.length; y++) {
				s = s+"<div class=\"index_choosemode_one_right_city_down_item\">"+data.data[y].city+"</div>"
					 +"<font class=\"hidden\">"+data.data[y].city+"</font>";						
			};
			$("div.index_choosemode_one_right_city_down").html(s);
			setCity();//只有在生成结构之后才能对结构进行绑定事件
		},
		error : function() {
			console.log("访问失败");
		},
		complete : function() {
			console.log("请求完成");
		},
	});
}
//绑定banner城市选择点击事件
var setCity = function(){
	var len = $("div.index_choosemode_one_right_city_down_item").length;
	for(var i=0;i<len;i++){
		$("div.index_choosemode_one_right_city_down_item:eq("+i+")").click(function(i){
			return function(e){
				e.stopPropagation();
				var city = $("div.index_choosemode_one_right_city_down>font:eq("+i+")").text() || $("div.index_choosemode_one_right_city_down:hidden>font:eq("+i+")").text();

				var index = $('.index_choosemode_left_item_choose').index()
				if ( index == 0 ){
					$("input#chooseGocity").val(city);
					$("input#chooseBackcity").val(city);
				}else if ( index == 1 ){
					$("input.quCar").val(city);
					// $("input.haiCar").val(city);
				}

				$("div.index_choosemode_one_right_city").addClass("hidden");
				console.log("city="+city);
			}		
		}(i))
	}

	$(document).on('click',function(e){
		e.stopPropagation();
		$("div.index_choosemode_one_right_city").addClass("hidden");
	})
}
//绑定banner选择多少城市点击事件
var clickcity = function(){
	for(var i=0;i<6;i++){
		$("div.index_choosemode_one_right_city_up_three_item:eq("+i+")").click(function(i){
			return function(e){
				e.stopPropagation();
				var type = i+1 ;
				wantCity(type);
				return false
			}			
		}(i));
	}

	for(var i=6;i<12;i++){
		$("div.index_choosemode_one_right_city_up_three_item:eq("+i+")").click(function(i){
			return function(e){
				e.stopPropagation();
				var type = i-6+1 ;
				wantCity(type);
				return false
			}			
		}(i));
	}
}
//请求banner接口
var wantBanner = function(){
	$.ajax({
		dataType : "json",
		type : "get",
		url : basePath+"/bannar",
		data : {		
		},
		contentType : "application/json",

		success : function(data) {


			for (var i = 0; i < data.data.length; i++) {
				(function(){
					var a = data.data[i].picture;
					var b=i+1;
				    var imgobj = new Image();
				    imgobj.src = a
				    imgobj.onload = function () {
				       var html = '<div class="swiper-slide red-slide" style="background:url('+ a +');background-position:center center;"></div>'
						console.log(1)
				       $(".swiper-wrapper").append(html);
				    };
				    
				})(i)
			};
			console.log($(".swiper-wrapper"))
			 var mySwiper = new Swiper('.swiper-container',{
			    pagination: '.pagination',
			    paginationClickable: false,
			    moveStartThreshold: 100,
			    loop:true,
			    autoplay:3000,
			})
			console.log("banner")
		},
		error : function() {
			console.log("访问失败");
		},
		complete : function() {
			console.log("请求完成");
		},
	});
}
//首页轻松租车请求
var requestRent = function(){
	$.ajax({
				dataType : "json",
				type : "get",
				url : basePath+"/nav",
				data : {
					type : 1
				},
				contentType : "application/x-www-form-urlencoded;charset=utf-8",

				success : function(data) {
					var s = "";
					for (var i = 0; i < data.data.length; i++) {
						s = s
								+ "<div class=\"col-lg-3 col-md-3 index_adcontent_content_item shand\" >"
								+ "<div class=\"index_adcontent_content_item_img\">"
								+ "<img src="
								+ data.data[i].picture
								+ " class=\"img-responsive\" />"
								+ "</div>"
								+ "<div class=\"index_adcontent_content_item_detail clearfix\">"
								+ "<div class=\"index_adcontent_content_item_detail_right clearfix\">"
								+ "<div class=\"index_adcontent_content_item_detail_right_three\">起</div>"
								+ "<div class=\"index_adcontent_content_item_detail_right_two\">"
								+ data.data[i].price
								+ "</div>"
								+ "<div class=\"index_adcontent_content_item_detail_right_one\">¥</div>"
								+ "</div>"
								+ "<div class=\"index_adcontent_content_item_detail_left\">"
								+ "<div class=\"index_adcontent_content_item_detail_left_city\">"
								+ data.data[i].city
								+ "</div>"
								+ "<div class=\"index_adcontent_content_item_detail_left_car\">"
								+ data.data[i].title + "</div>" + "</div>"
								+ "</div>" + "</div>"+"<font class=\"hidden\">"+data.data[i].id+"</font>";
						
					};
					;
					/* $("#img"+i).attr("src",data.data[i-1].picture); */
					$(".index_adcontent_content_ajax").html(s);
					rentGoto();//只有在生成结构之后才能对结构进行绑定事件
				},
				error : function() {
					console.log("访问失败");
				},
				complete : function() {
					console.log("请求完成");
				},
			});

};
//点击轻松租车下面车辆信息跳转
var rentGoto = function(){
	if(choosetype == "轻松租车"){
		for(var i=0;i<4;i++){
			$("div.index_adcontent_content_ajax>div.index_adcontent_content_item:eq("+i+")").click(function(i){
				return function(e){
					e.stopPropagation();
					var rentcity  = $("div.index_adcontent_content_item_detail_left_city:eq("+i+")").text();
					var url = basePath+"/rentlist?rentcity="+rentcity;
					url = encodeURI(url);
					url = encodeURI(url);
					window.location.href = (url);					
				}
			}(i));
		}
	}else{
		for(var i=0;i<4;i++){
			$("div.index_adcontent_content_ajax>div.index_adcontent_content_item:eq("+i+")").click(function(i){
				return function(e){
					e.stopPropagation();
					var lineid = $("div.index_adcontent_content_ajax>font.hidden:eq("+i+")").text();
					var linecity  = $("div.index_adcontent_content_item_detail_left_city:eq("+i+")").text();
					var url = basePath+"/lineinfo?linecity="+linecity+"&lineid="+lineid;
					url = encodeURI(url);
					url = encodeURI(url);
					window.location.href = (url);
					console.log("lineid为"+$("div.index_adcontent_content_ajax>font.hidden:eq("+i+")").text());
				}
			}(i));
		}
	}
	
}
//首页点击轻松租车请求
var requestRentClick = function(){
	$("#requestRent").click(function(e){
		e.stopPropagation();
		requestRent();
		$("input.index_adhead_content_choose:eq(0)").addClass("yellowb");
		$("input.index_adhead_content_choose:eq(1)").removeClass("yellowb");
		choosetype = "轻松租车";
		console.log("轻松租车");
	});
};
//首页热门路线请求
var requestLine = function() {
	$.ajax({
				dataType : "json",
				type : "get",
				url : basePath+"/nav",
				data : {
					type : 2
				},
				contentType : "application/x-www-form-urlencoded;charset=utf-8",

				success : function(data) {
					
					var s = "";
					for (var i = 0; i < data.data.length; i++) {
						s = s
								+ "<div class=\"col-lg-3 col-md-3 index_adcontent_content_item shand\">"
								+ "<div class=\"index_adcontent_content_item_img\">"
								+ "<img src="
								+ data.data[i].picture
								+ " class=\"img-responsive\" />"
								+ "</div>"
								+ "<div class=\"index_adcontent_content_item_detail clearfix\">"
								+ "<div class=\"index_adcontent_content_item_detail_right clearfix\">"
								+ "<div class=\"index_adcontent_content_item_detail_right_three\">起</div>"
								+ "<div class=\"index_adcontent_content_item_detail_right_two\">"
								+ data.data[i].price
								+ "</div>"
								+ "<div class=\"index_adcontent_content_item_detail_right_one\">¥</div>"
								+ "</div>"
								+ "<div class=\"index_adcontent_content_item_detail_left\">"
								+ "<div class=\"index_adcontent_content_item_detail_left_city\">"
								+ data.data[i].city
								+ "</div>"
								+ "<div class=\"index_adcontent_content_item_detail_left_car\">"
								+ data.data[i].title + "</div>" + "</div>"
								+ "</div>" + "</div>"+"<font class=\"hidden\">"+data.data[i].id+"</font>";
					};
					$(".index_adcontent_content_ajax").html(s);
					rentGoto();

				},
				error : function() {
					console.log("访问失败");
				},
				complete : function() {
					console.log("请求完成");
				},
			});

};
//首页点击热门线路请求
var requestLineClick = function(){
	$("#requestLine").click(function(e){
		e.stopPropagation();
		requestLine();
		console.log("热门路线");
		$("input.index_adhead_content_choose:eq(1)").addClass("yellowb");
		$("input.index_adhead_content_choose:eq(0)").removeClass("yellowb");
		choosetype = "热门线路";
		
	})
};
//请求首页国内租车城市
var requestChinacity = function(){
	$.ajax({
		dataType : "json",
		type : "get",
		url : basePath+"/navcity",
		data : {
			
		},
		contentType : "application/x-www-form-urlencoded;charset=utf-8",

		success : function(data) {
			var s = "";
			for (var i = 0; i < data.data.length; i++) {
				s = s+ "<div class=\"index_rentcontent_up_left\" onclick='requestChinacityinfo(\""+data.data[i].city+"\")'>"+data.data[i].city+"</div>"
			}
			;
			$(".index_rentcontent_up").prepend(s);

			$('.index_rentcontent_up_left').eq(0).addClass('active')
			

		},
		error : function() {
			console.log("访问失败");
		},
		complete : function() {
			console.log("请求完成");
		},
	});
}
//首页国内租车深圳，广州等城市等租车信息请求
var requestChinacityinfo = function(chinacity){
	
	$.ajax({		
		dataType : "json",
		type : "post",
		url : basePath+"/navcar",
		data : {
			city:chinacity
		},
		
		contentType : "application/x-www-form-urlencoded;charset=utf-8",
		success : function(data) {
			var s = "";
			for (var i = 0; i < data.data.length; i++) {
				s = s
						+ "<div class=\"col-lg-3 col-md-3 index_adcontent_content_item shand\">"
						+ "<div class=\"index_adcontent_content_item_img\">"
						+ "<img src="
						+ data.data[i].picture
						+ " class=\"img-responsive index_adcontent_content_item_img_posi\" />"
						+ "</div>"
						+ "<div class=\"index_adcontent_content_item_detail clearfix\">"
						+ "<div class=\"index_adcontent_content_item_detail_right clearfix\">"
						+ "<div class=\"index_adcontent_content_item_detail_right_three\">起</div>"
						+ "<div class=\"index_adcontent_content_item_detail_right_two\">"
						+ data.data[i].price
						+ "</div>"
						+ "<div class=\"index_adcontent_content_item_detail_right_one\">¥</div>"
						+ "</div>"
						+ "<div class=\"index_adcontent_content_item_detail_left\">"
						+ "<div class=\"index_adcontent_content_item_detail_left_city\">"
						+ data.data[i].title
						+ "</div>"
						+ "<div class=\"index_adcontent_content_item_detail_left_car\">"
						+ data.data[i].city + "</div>" + "</div>"
						+ "</div>" + "</div>"
						+"<font class=\"hidden\">"+data.data[i].id+"</font>";
			
			}
			;
			$(".index_rentcontent_down_ajax").html(s);
			chinacityGoto();
			
			
		},
		error : function() {
			console.log("访问失败");
		},
		complete : function() {
			console.log("请求完成");
		},
	});
}
//点击国内租车内容时候跳转绑定事件
var chinacityGoto = function(){
	for(var z=0;z<4;z++){
		$("div.index_rentcontent_down_ajax>div:eq("+z+")").click(function(z){
			return function(e){
				e.stopPropagation();
				var carid=$("div.index_rentcontent_down_ajax>font:eq("+z+")").text();
				var rentcity = $("div.index_rentcontent_down_ajax div.index_adcontent_content_item_detail_left_car:eq("+z+")").text();
				var url = basePath+"/rentlist?rentcity="+rentcity;
				url = encodeURI(url);
				url = encodeURI(url);
				window.location.href = (url);	
			}		
		}(z));
	};
}
//首页经典路线点击当即热玩，面朝大海等时的请求
var wantLine = function(linetype){
	var lineimgb = basePath+"/static/pcsofangche/line/lineindex/img/";
	$.ajax({	
		dataType : "json",
		type : "post",
		url : basePath+"/navline",
		data : {
			type:linetype
		},		
		contentType : "application/x-www-form-urlencoded;charset=utf-8",
		success : function(data) {
			$("div.index_tourcontent_down_big_icon>img").attr("src",data.data[0].picture);
			$("div.index_tourcontent_down_big_title").text(data.data[0].title);
			$("div.index_tourcontent_down_big_center_right_two").text(data.data[0].price);
			$("div.index_tourcontent_down_big_center_left").text(data.data[0].city);
			var lineid="<font class=\"hidden\">"+data.data[0].id+"</font>"
			$("div.index_tourcontent_down_big").prepend(lineid);
			$("div.index_tourcontent_down_big_content").html("");
			for(var i=0;i<data.data[0].charact.length;i++){
				var charact="";
				charact=charact+"<div class=\"index_tourcontent_down_big_content_item\">"+data.data[0].charact[i].name+"</div>"			
				$("div.index_tourcontent_down_big_content").prepend(charact);
			};
			var cityinfo="";
//			for (var i = 1; i < data.data.length; i++) {
//				cityinfo = cityinfo
//						+ "<div class=\"col-lg-4 col-md-4 index_adcontent_content_item shand\">"
//						+ "<div class=\"index_adcontent_content_item_img\">"
//						+ "<img src="
//						+ data.data[i].picture
//						+ " class=\"img-responsive\" />"
//						+ "</div>"
//						+ "<div class=\"index_adcontent_content_item_detail clearfix\">"
//						+ "<div class=\"index_adcontent_content_item_detail_right clearfix\">"
//						+ "<div class=\"index_adcontent_content_item_detail_right_three\">起</div>"
//						+ "<div class=\"index_adcontent_content_item_detail_right_two\">"
//						+ data.data[i].price
//						+ "</div>"
//						+ "<div class=\"index_adcontent_content_item_detail_right_one\">¥</div>"
//						+ "</div>"
//						+ "<div class=\"index_adcontent_content_item_detail_left\">"
//						+ "<div class=\"index_adcontent_content_item_detail_left_city\">"
//						+ data.data[i].city
//						+ "</div>"
//						+ "<div class=\"index_adcontent_content_item_detail_left_car\">"
//						+ data.data[i].title + "</div>" + "</div>"
//						+ "</div>" + "</div>"
//						+"<font class=\"hidden\">"+data.data[i].id+"</font>";		
//			};
			for(var i =1;i<data.data.length;i++){
				cityinfo = cityinfo + 
				"<div class=\"col-lg-4 col-md-4 lineindex_hot_center_item shand\">\n" +
				"<div class=\"lineindex_hot_center_item_icon\">\n" +
				"<img src=\""+data.data[i].picture+"\" class=\"lineindex_hot_center_item_icon_posi img-responsive\">\n" +
				"</div>\n" +
				"<div class=\"index_hot_center_item_center clearfix\">\n" +
				"<div class=\"lineindex_hot_center_item_center_city clearfix\">\n" +
				"<div class=\"lineindex_hot_center_item_center_city_icon\">\n" +
				"<img src=\""+lineimgb+"lineindex_city_small.png\" class=\"lineindex_hot_center_item_center_city_icon_posi\">\n" +
				"</div>\n" +
				"<div class=\"lineindex_hot_center_item_center_city_word\">出发地：</div>\n" +
				"<div class=\"lineindex_hot_center_item_center_city_city\">"+data.data[i].city+"</div>\n" +
				"</div>\n" +
				"<div class=\"lineindex_hot_center_item_center_price clearfix\">\n" +
				"<div class=\"lineindex_hot_center_item_center_price_one\">起</div>\n" +
				"<div class=\"lineindex_hot_center_item_center_price_two\">"+data.data[i].price+"</div>\n" +
				"<div class=\"lineindex_hot_center_item_center_price_three\">￥</div>\n" +
				"</div>\n" +
				"</div>\n" +
				"<div class=\"lineindex_hot_center_item_title\">"+data.data[i].title+"</div>\n" +
				"</div>"+"<font class=\"hidden\">"+data.data[i].id+"</font>"
			}
			$("div.index_tourcontent_down_normal_ajax").html(cityinfo);
			lineGoto();
			
			
			
		},
		error : function() {
			console.log("访问失败");
		},
		complete : function() {
			console.log("请求完成");
		},
	});
}
//首页经典路线点击当季热玩，面朝大海时绑定事件触发请求
var wantHotLine = function(){
	$('.index_tourcontent_up_item').eq(0).addClass('active')
	for(var a=0;a<4;a++){
		$("div.index_tourcontent_up_item:eq("+a+")").click(function(a){
			return function(e){
				e.stopPropagation();
				var type=$("div.index_tourcontent_up_item:eq("+a+")").data("name");
				$("div.index_tourcontent_up_item").removeClass('active')
				$(this).addClass('active')
				wantLine(type);
			}		
		}(a));
	}
}
//首页点击经典路线下的内容跳转绑定事件
var lineGoto = function(){
	$("div.index_tourcontent_down_big").click(function(e){
		e.stopPropagation();
		var lineid = $("div.index_tourcontent_down_big>font").text();
		var linecity = $("div.index_tourcontent_down_big_center_left").text();
		var url = basePath+"/lineinfo?lineid="+lineid+"&linecity="+linecity;
		url = encodeURI(url);
		url = encodeURI(url);
		window.location.href = (url);	
	});
	for(var y=0;y<6;y++){
		$("div.index_tourcontent_down_normal_ajax>div:eq("+y+")").click(function(y){
			return function(e){
				e.stopPropagation();
				var linecity = $("div.index_tourcontent_down_normal_ajax div.lineindex_hot_center_item_center_city_city:eq("+y+")").text();
				var lineid = $("div.index_tourcontent_down_normal_ajax font:eq("+y+")").text();
				var url = basePath+"/lineinfo?lineid="+lineid+"&linecity="+linecity;
				url = encodeURI(url);
				url = encodeURI(url);
				window.location.href = (url);
			}		
		}(y));
	}
}
//更多跳转
var gotoLineIndex = function(){
	$("div.index_tourcontent_up_more").click(function(e){
		e.stopPropagation();
		window.location.href = (basePath+"/lineindex");
	});
	$("div.index_rentcontent_up_right").click(function(e){
		e.stopPropagation();
		window.location.href = (basePath+"/rentindex");
	});
}
//初始化出发时间返程时间
var PageLoadTime = function(){
$.ajax({		
		dataType : "json",
		type : "post",
		url : basePath+"/indexFormaltime",
		data : {
			
		},
		
		contentType : "application/x-www-form-urlencoded;charset=utf-8",
		success : function(data) {
			var start = data.data.start;
			var end = data.data.end;
			$("input#chooseGotime").val(start);
			$("input#chooseBacktime").val(end);
		},
		error : function() {
			console.log("访问失败");
		},
		complete : function() {
			console.log("请求完成");
		},
	});
}
//banner房车旅行栏请求城市精选
var WantHotCity = function(){
	var loading = layer.load();
	$.ajax({
		dataType : "json",
		type : "post",
		url : basePath+"/line/cityinfo",
		data : {
			
		},
		contentType : "application/x-www-form-urlencoded;charset=utf-8",

		success : function(data) {
			var a = "";
			for(var i = 0;i<data.data.datashot.length;i++){
				a = a + "<div class=\"index_choosemode_two_hot_item_item\">"+data.data.datashot[i].city+"</div>"
			};
			$("div.index_choosemode_two_hot_item").html(a);
			SearchHotCity();
			
		},
		error : function() {
			console.log("访问失败");
		},
		complete : function() {
			console.log("请求完成");
			layer.close(loading);
		},
	});
}
//点击城市精选及搜索跳转绑定
var SearchHotCity = function(){
	var length = $("div.index_choosemode_two_hot_item_item").length;
	for(var i = 0;i<length;i++){
		$("div.index_choosemode_two_hot_item_item:eq("+i+")").click(function(i){
			return function(e){
				e.stopPropagation();
				var city = $("div.index_choosemode_two_hot_item_item:eq("+i+")").text();
				$("input.index_choosemode_two_destinaton_input_input").val(city);
				console.log("city="+city);
			}
		}(i))
	};
	$("button.index_choosemode_two_b").click(function(e){
		e.stopPropagation();
		var city = $("input.index_choosemode_two_destinaton_input_input").val();
		var url = basePath+"/linelist?linecity="+city;
		url = encodeURI(url);
		url = encodeURI(url);
		window.location.href = (url);
	});
}


/**
 * 自定义弹窗
 */

function popup(ele,text){
	ele.html(text)
	ele.show()
	var timer 
	clearTimeout(timer)
	timer = setTimeout(function() {
		ele.hide()
	}, 4000);
}

/**
 * 长租服务
 */

$(document).on('click','.button',function(){
	var quCar = $('.quCar').val()
	var haiCar = $('.haiCar').val()
	var numDays = $('.numDays').val()
	var numPeople = $('.numPeople').val()
	var contacts = $('.contacts').val()
	var phone = $('.phone').val()

	if ( !quCar ){
		popup($('.choosemode_popup'),'请选择取车城市')
		// layer.msg('请选择取车城市');
		return false
	}
	if ( !haiCar ){
		popup($('.choosemode_popup'),'请选择还车时间')
		// layer.msg('请选择还车城市');
		return false
	}
	if ( !numDays ){
		popup($('.choosemode_popup'),'请输入租期天数')
		// layer.msg('请输入租期天数');
		return false
	}
	if ( !numPeople ){
		popup($('.choosemode_popup'),'请输入出现人数')
		// layer.msg('请输入出现人数');
		return false
	}
	if ( !contacts ){
		popup($('.choosemode_popup'),'请输入联系人')
		// layer.msg('请输入联系人');
		return false
	}
	if ( !phone ){
		$('.choosemode_popup').html('请输入联系电话')
		$('.choosemode_popup').show()
		var timer = setTimeout(function() {
			$('.choosemode_popup').hide()
		}, 2000);
		// layer.msg('请输入联系电话');
		return false
	}
	
	var data  = {
		pickCarCity:quCar,
		pickCarTime:haiCar,
		rentDay:parseInt(numDays),
		travelNum:parseInt(numPeople),
		contact:contacts,
		contactPhone:phone,
	}

	$.ajax({
		dataType : "json",
		type : "post",
		url : basePath+"/saveRentCar",
		data : JSON.stringify(data),
		contentType : "application/json",
		success : function(data) {
			if ( data.respCode == 1 ){
				$('.choosemode_popup').html('提交成功！')
				$('.choosemode_popup').show()
				var timer = setTimeout(function() {
					$('.choosemode_popup').hide()
				}, 2000);
				
			}
		}
	})
})


/**
 * 国内租车点击在颜色
 */
$(document).on('click','.index_rentcontent_up_left',function(){
	$('.index_rentcontent_up_left').removeClass('active')
	$(this).addClass('active')
})